package com.mcflies.commons;

import java.util.List;

import com.mcflies.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-14
 * @comment:下拉刷新自定义Adapter
 */
public class PullDownToRefreshAdapter extends BaseAdapter {
	private Context context;
	private List<String> dataList;
	private LayoutInflater inflater;

	public PullDownToRefreshAdapter() {
	}

	public PullDownToRefreshAdapter(Context context, List<String> dataList) {
		this.context = context;
		this.dataList = dataList;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (null == view) {
			view = inflater.inflate(
					R.layout.pull_down_to_refresh_listview_item, null);
		}

		TextView pullDownToRefreshListViewItem_TV = (TextView) view
				.findViewById(R.id.pullDownToRefreshListViewItem_TV);
		pullDownToRefreshListViewItem_TV.setText(dataList.get(position));
		return view;
	}
}
